package com.hanrui.android.fragment.message.audit.contract;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.activity.download.MyDownLoadActivity;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.FilesBean;
import com.hanrui.android.model.GuaranteeContractDetailBean;
import com.hanrui.android.net.contract.message.audit.contract.GuaranteeContractDetailContract;
import com.hanrui.android.net.presenter.message.audit.contract.GuaranteeContractDetailPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 担保合同审批基本信息
 *
 */

public class GuaranteeContractDetailFragment extends BaseFragment<GuaranteeContractDetailPresenter> implements GuaranteeContractDetailContract.View {
    @BindView(R.id.main_title)
    TextView mainTitle;
    @BindView(R.id.subhead_title)
    TextView subheadTitle;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.thing_title)
    TextView thingTitle;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.page_num)
    TextView pageNum;
    @BindView(R.id.copies_num)
    TextView copiesNum;
    @BindView(R.id.leaders)
    TextView leaders;
    @BindView(R.id.time_limit)
    TextView timeLimit;
    @BindView(R.id.record_company)
    TextView recordCompany;
    @BindView(R.id.party_b)
    TextView partyB;
    @BindView(R.id.agent)
    TextView agent;
    @BindView(R.id.department_head)
    TextView departmentHead;
    @BindView(R.id.seal_date)
    TextView sealDate;
    @BindView(R.id.money_company)
    TextView moneyCompany;
    @BindView(R.id.max_timelimit)
    TextView maxTimeLimit;
    @BindView(R.id.transaction_content)
    TextView transactionContent;
    @BindView(R.id.money_biao)
    TextView moneyBiao;
    @BindView(R.id.enclosure)
    ImageView enclosure;
    @BindView(R.id.assign_body)
    TextView assignBody;
    @BindView(R.id.taxation)
    TextView taxation;
    @BindView(R.id.reson)
    TextView reson;
    @BindView(R.id.duty_people)
    TextView dutyPeople;
    @BindView(R.id.from)
    TextView from;
    @BindView(R.id.vote_meet)
    TextView voteMeet;
    @BindView(R.id.money_meet)
    TextView moneyMeet;
    @BindView(R.id.wind_meet)
    TextView windMeet;
    @BindView(R.id.party_meet)
    TextView partyMeet;
    @BindView(R.id.group_meet)
    TextView groupMeet;
    @BindView(R.id.director_meet)
    TextView directorMeet;
    @BindView(R.id.work_content)
    TextView workContent;
    @BindView(R.id.enclosure_ll)
    LinearLayout enclosureLl;
    @BindView(R.id.enclosure_num)
    TextView enclosureNum;

    List<FilesBean> fileList = new ArrayList<>();

    String taskId,procInsId,bizId;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_guaranteecontractdetail;
    }

    @Override
    protected void initInjector() {
        mFragmentComponent.inject(this);
    }

    @Override
    protected void initView(View view) {

        taskId = getArguments().getString("taskId");
        procInsId = getArguments().getString("procInsId");
        bizId = getArguments().getString("bizId");

        mPresenter.guaranteeContractBizDetail(getActivity(),taskId,procInsId,bizId);

    }



    public static GuaranteeContractDetailFragment newInstance(String taskId, String procInsId, String bizId) {
        GuaranteeContractDetailFragment fragment = new GuaranteeContractDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putString("taskId", taskId);
        bundle.putString("procInsId", procInsId);
        bundle.putString("bizId", bizId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @OnClick({R.id.enclosure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.enclosure:
                MyDownLoadActivity.start(getActivity(),fileList);
                break;
        		}
    }

    @Override
    public void guaranteeContractBizDetail(GuaranteeContractDetailBean data) {

        if (null != data) {

            mainTitle.setText(data.getDetail().getAgentName()+"的担保合同审批");
            subheadTitle.setText(data.getDetail().getUpdateDate());
            name.setText(data.getDetail().getName());
            thingTitle.setText(data.getDetail().getUpdateDate());
            time.setText(data.getDetail().getOfficeName());
            pageNum.setText(data.getDetail().getPages());
            copiesNum.setText(data.getDetail().getCopies());
            leaders.setText(data.getDetail().getGuaranteeName());
            timeLimit.setText(data.getDetail().getLimitTime());
            recordCompany.setText(data.getDetail().getStorageUnit());
            partyB.setText(data.getDetail().getSecuredParty());
            agent.setText(data.getDetail().getAgentName());
            departmentHead.setText(data.getDetail().getLeaderPerson());
            sealDate.setText(data.getDetail().getSignedDate());
            moneyCompany.setText(data.getDetail().getFinancialUnit());
            maxTimeLimit.setText(data.getDetail().getStartTime()+"至"+data.getDetail().getEndTime());
            transactionContent.setText(data.getDetail().getContent());
            moneyBiao.setText(data.getDetail().getLimit());
            assignBody.setText(data.getDetail().getPayTypeName());
            taxation.setText(data.getDetail().getTaxFee());
            reson.setText(data.getDetail().getRemarks());
            dutyPeople.setText(data.getDetail().getTypeName());
            from.setText(data.getDetail().getMeetName());
            voteMeet.setText(data.getDetail().getVoteName());
            moneyMeet.setText(data.getDetail().getCapitalName());
            windMeet.setText(data.getDetail().getRiskExamineName());
            partyMeet.setText(data.getDetail().getCommitteeName());
            groupMeet.setText(data.getDetail().getMeetingApplyName());
            directorMeet.setText(data.getDetail().getDirectorsName());
            workContent.setText(data.getDetail().getContent());

            if (null != data.getFiles() && data.getFiles().size() > 0) {

                enclosureLl.setVisibility(View.VISIBLE);
                enclosureNum.setText("["+data.getFiles().size()+"]");
                fileList.clear();
                fileList.addAll(data.getFiles());

            }



            }

    }
}
